package com.blockmeta.bbs.businesslibrary.widget;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.SparseIntArray;

import com.blockmeta.bbs.businesslibrary.pojo.MainTabPOJO;

import java.util.List;

import static com.blockmeta.bbs.businesslibrary.launch.navigationYMAL.sMainTabPOJO;

/**
 * @author AirThor
 * @date 2019/10/16.
 */
public class BbsGroupTag extends RoundCornerTextView {
    /** 这个tag对应的tablayout上的位置*/
    private int mTabPosition = 0;
    /** 综合节点 */
    private final static int SYNTHESIS=61;
    /** 项目节点 */
    private final static int PROJECT=182;
    /** 技术节点 */
    private final static int TECHNOLOGY=43;
    /** 平台节点 */
    private final static int PLATFORM=183;
    /** 默认 */
    private final static int DEFAULT = 0;

    private static final SparseIntArray mBackgrounds = new SparseIntArray();
//    private static final SparseIntArray mTextColor = new SparseIntArray();

    static {
        mBackgrounds.put(SYNTHESIS, Color.parseColor("#FCE0E0"));
        mBackgrounds.put(PROJECT,Color.parseColor("#FDECE0"));
        mBackgrounds.put(TECHNOLOGY,Color.parseColor("#FFFAE0"));
        mBackgrounds.put(PLATFORM,Color.parseColor("#E1F4E9"));
        mBackgrounds.put(DEFAULT,Color.parseColor("#E0F3F1"));

//        mTextColor.put(SYNTHESIS, Color.parseColor("#EE0000"));
//        mTextColor.put(PROJECT,Color.parseColor("#F56A00"));
//        mTextColor.put(TECHNOLOGY,Color.parseColor("#FFD600"));
//        mTextColor.put(PLATFORM,Color.parseColor("#0FAA52"));
//        mTextColor.put(DEFAULT,Color.parseColor("#00A494"));
    }

    public BbsGroupTag(Context context) {
        super(context);
    }

    public BbsGroupTag(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public BbsGroupTag(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setTagName(String tagName,int id){
        mTabPosition = 0;
        if (sMainTabPOJO==null|| TextUtils.isEmpty(tagName)) {return;}
        List<MainTabPOJO.ChainnodeBean> chainnode = sMainTabPOJO.getChainnode();
        int chainnodeSize = chainnode.size();
        int currentGroup = DEFAULT;

        out: for (int i = 0; i < chainnodeSize; i++) {
            currentGroup = chainnode.get(i).getId();
            if (currentGroup!=SYNTHESIS&&currentGroup!=PROJECT&&currentGroup!=PLATFORM&&currentGroup!=TECHNOLOGY){
                currentGroup = DEFAULT;
                continue ;
            }
            List<MainTabPOJO.ChainnodeBean.SubBean> sub = chainnode.get(i).getSub();
            for (int j = 0; j < sub.size(); j++) {
                if (id == sub.get(j).getId()){
                    break out;
                }
                mTabPosition++;
            }
        }

        setText(tagName);

        try {
            setBackGroundColor(mBackgrounds.get(currentGroup));
//            setTextColor(mTextColor.get(currentGroup));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int getTabPosition() {
        return mTabPosition;
    }
}
